package com.winz.cultureapp.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.winz.cultureapp.R;
import com.winz.cultureapp.base.BaseAppCompatActivity;
import com.winz.cultureapp.constants.Constants;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 展馆详情
 */
public class ExhibitionDesActivity extends BaseAppCompatActivity {
    @BindView(R.id.tv_top_title)
    TextView mTv_top_title;
    @BindView(R.id.wv_content)
    WebView mWv_news;
    private String id ;
    private String href ;

    @Override
    protected int contentView() {
        return R.layout.activity_exhibition_des;
    }

    @Override
    protected void initViews() {
        mWv_news.getSettings().setJavaScriptEnabled(true);//设置WebView支持JS
        mWv_news.getSettings().setDefaultTextEncodingName("utf-8");//设置解码时的字符集
        mWv_news.getSettings().setLoadWithOverviewMode(true);
        mWv_news.getSettings().setUseWideViewPort(true);
        mWv_news.getSettings().setSupportZoom(true);
        mWv_news.getSettings().setBuiltInZoomControls(true);
        mWv_news.getSettings().setDomStorageEnabled(true);
        mWv_news.getSettings().setBuiltInZoomControls(false);
        mWv_news.setWebViewClient(new WebViewClient() {
            /*
            此处能拦截超链接的url,即拦截href请求的内容.
            */
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Uri uri = Uri.parse(url);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                return true;
            }

        });

    }
    @Override
    protected void loadDatas(Intent intent) {
        if (intent != null){
            if (intent.getExtras() != null){
                id = intent.getExtras().getString(Constants.KEY.NEWS.ID);
                href = intent.getExtras().getString(Constants.KEY.NEWS.HREF);
                String top_title = intent.getExtras().getString(Constants.KEY.NEWS.TOP_TITLE);

                mTv_top_title.setText(top_title);
                mWv_news.loadUrl(href);
            }
        }
    }


    @OnClick({R.id.fl_back,R.id.tv_join})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.fl_back:
                finish();
                break;
            case R.id.tv_join:
                Bundle bundle = new Bundle();
                bundle.putString(Constants.KEY.EXHIBITION.ITEM_ID,id);
                startActivity(BookExplainActivity.class,false,bundle);
                break;
        }
    }

}
